/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Andre
 */
@Entity
@Table(name = "exercicio")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Exercicio.findAll", query = "SELECT e FROM Exercicio e"),
    @NamedQuery(name = "Exercicio.findByIdExercicio", query = "SELECT e FROM Exercicio e WHERE e.idExercicio = :idExercicio"),
    @NamedQuery(name = "Exercicio.findByDescricao", query = "SELECT e FROM Exercicio e WHERE e.descricao = :descricao")})
public class Exercicio implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idExercicio")
    private Integer idExercicio;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 80)
    @Column(name = "descricao")
    private String descricao;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "exercicio")
    private List<ItensFicha> itensFichaList;
    
    @JoinColumn(name = "idMaquina", referencedColumnName = "idProduto")
    @ManyToOne(optional = false)
    private Produto maquina;

    public Exercicio() {
    }

    public Exercicio(String descricao) {
        this.descricao = descricao;
    }

    public Integer getIdExercicio() {
        return idExercicio;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    @XmlTransient
    public List<ItensFicha> getItensFichaList() {
        return itensFichaList;
    }

    public void setItensFichaList(List<ItensFicha> itensFichaList) {
        this.itensFichaList = itensFichaList;
    }

    public Produto getMaquina() {
        return maquina;
    }

    public void setMaquina(Produto maquina) {
        this.maquina = maquina;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idExercicio != null ? idExercicio.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Exercicio)) {
            return false;
        }
        Exercicio other = (Exercicio) object;
        if ((this.idExercicio == null && other.idExercicio != null) || (this.idExercicio != null && !this.idExercicio.equals(other.idExercicio))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Exercicio[ idExercicio=" + idExercicio + " ]";
    }
    
}
